﻿using System;
using System.Text;
using System.Data;
using System.Data.OleDb;
using System.Collections.Generic;
using System.Reflection;
namespace Data
{
	 	//UsersAccount
		public class UsersAccount
	{	
		/// <summary>
        /// 主键
        /// </summary>
        private readonly string primaryKey= "Id";
		/// <summary>
        /// 添加
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public long Add(Model.UsersAccount model)
        {
            return new DataAccess().Add<Model.UsersAccount>(model, primaryKey);
        }
        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public int Update(Model.UsersAccount model)
        {
            return new DataAccess().Update<Model.UsersAccount>(model, primaryKey);
        }
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        public bool Delete(long Id)
        {
            return new DataAccess().Delete<Model.UsersAccount>(Id, primaryKey);
        }
        /// <summary>
        /// 单条
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        public Model.UsersAccount GetModel(long Id)
        {
            return new DataAccess().Get<Model.UsersAccount>(Id, primaryKey);
        }
        public Model.UsersAccount GetModeluser_id(long user_id)
        {
            return new DataAccess().Get<Model.UsersAccount>(user_id, "user_id");
        }
        public Model.UsersAccount GetModelBytouz_user_id(long touz_user_id)
        {
            return new DataAccess().Get<Model.UsersAccount>(touz_user_id, "user_id");
        }
        public Model.UsersAccount GetModelByuser_id(long user_id)
        {
            return new DataAccess().Get<Model.UsersAccount>(user_id, "user_id");
        }
        /// <summary>
        /// 总数据数
        /// </summary>
        /// <returns></returns>
        public int GetAll_Count()
        {
            return new DataAccess().GetCount<Model.UsersAccount>(primaryKey);
        }
        /// <summary>
        /// 抽取分页数据
        /// </summary>
        public List<Model.UsersAccount> GetPageList_Where(int PageIndex, int PageSize, long user_id,out int totalCount)
        {          
            string strWhere = GetSqlWhere(user_id);
            totalCount = new DataAccess().GetCount<Model.UsersAccount>(primaryKey, strWhere);
            return new DataAccess().GetPage_List<Model.UsersAccount>(PageIndex, PageSize, primaryKey, "user_id ", strWhere);
        }
        public List<Model.UsersAccount> getList(int PageIndex, int PageSize, out int totalCount)
        {
            string strWhere = "1=1";
            totalCount = new DataAccess().GetCount<Model.UsersAccount>(primaryKey, strWhere);
            return new DataAccess().GetPage_List<Model.UsersAccount>(PageIndex, PageSize, primaryKey, "winTotal desc", strWhere);
        }
        /// <summary>
        /// 拼接条件
        /// </summary>
        public string GetSqlWhere(long user_id)
        {
            StringBuilder sqlWhere = new StringBuilder();

            sqlWhere.Append(" 1>0");

             sqlWhere.Append(" and user_id = '" + user_id + "'");
                   
            return sqlWhere.ToString();
        }
        /// <summary>
        /// 批删
        /// </summary>
        /// <param name="Ids"></param>
        /// <returns></returns>
        public int Drop(string Ids)
        {
            return new DataAccess().Drop<Model.UsersAccount>(Ids, primaryKey);
        }

        //-----------------------------------------
        public List<Model.UsersAccount> GetPageListWhere(int PageIndex, int PageSize, string sql, out int totalCount)
        {
            totalCount = new DataAccess().GetCount<Model.UsersAccount>(primaryKey, sql);
            return new DataAccess().GetPage_List<Model.UsersAccount>(PageIndex, PageSize, primaryKey, primaryKey + " desc", sql);
        }


        public DataTable GetPageListBysql(string sql)
        {
            return DbHelp.ExecuteDataset(DBConfig.ConnectionSettings, CommandType.Text, sql, null).Tables[0];

            //totalCount = new DataAccess().GetCount<Model.LotteryChippedUser>(primaryKey, sql);
            //return new DataAccess().GetPage_List<Model.LotteryChippedUser>(PageIndex, PageSize, primaryKey, primaryKey + " desc", sql);
        }

     
        //---------------------------------------------------

        public int Update(string sql)
        {
            return DbHelp.ExecuteNonQuery(DBConfig.ConnectionSettings, CommandType.Text, sql, null);
        }

    }
}